package com.yeqiangwei.commons.util;

import java.io.File;


public class GetConfigFile {

	private String filename;

	public GetConfigFile(String filename) {
		this.filename = filename;
	}

	public File get() {
		File file = new File(Constants.ROOT_PATH + "conf" + File.separator + filename);
		if (file.exists()) {
			return file;
		}
		return get0();
	}

	private File get0() {
		File file = null;
		String _classpath = System.getProperty("java.class.path");
		String[] classpathList = _classpath.split(":");
		for (String classpath : classpathList) {
			File cfile = new File(classpath);
			if(cfile.isFile()) {
				file = new File(cfile.getParentFile().getAbsolutePath() + File.separator + filename);
			}
			else {
				file = new File(classpath + File.separator + filename);
			}
			if (file.exists()) {
				return file;
			}
		}
		return null;
	}
}
